package httpclient

import (
//"fmt"
)

const (
	DEF_CONTENT_TYPE = "application/json; charset=utf-8"

	HEADER_NAME_CONTENT_TYPE = "Content-Type"
)


type Options struct {
	UrlParams  map[string]string   //Url 中的参数 http://xxxxxx/  ? k=1&
	Headers    map[string]string   //Header
	//Body       interface{}		  //有body时 需要设置content-type

	Params 	   map[string]string   // 其他参数
	//Context context.Context
}

type Option func(*Options)

//Content
func WithContentType(value string) Option {
	return func(options *Options) {
		options.Headers[HEADER_NAME_CONTENT_TYPE] = value
	}
}

//Header 字段
func WithHeader(key, value string) Option {
	return func(options *Options) {
		options.Headers[key] = value
	}
}

//Header 字段
func WithHeaders(param map[string]string) Option {
	return func(options *Options) {
		//if nil != param {
		for k, v := range param {
			//fmt.Println("WithOptionParam ", k, v)
			options.Headers[k] = v
		}
		//}
	}
}

//Url 参数
func WithUrlParam(key, value string) Option {
	return func(options *Options) {
		options.UrlParams[key] = value
	}
}

//Url 参数
func WithUrlParams(param map[string]string) Option {
	return func(options *Options) {
		//if nil != param {
		for k, v := range param {
			//fmt.Println("WithOptionParam ", k, v)
			options.UrlParams[k] = v
		}
		//}
	}
}

////Body
//func WithBody(body interface{}) Option {
//	return func(options *Options) {
//		options.Body = body
//	}
//}



func WithOptionParams(param map[string]string) Option {
	return func(options *Options) {
		//if nil != param {
		for k, v := range param {
			options.Params[k] = v
		}
		//}
	}
}


func newHttpOptions(option ...Option) *Options{
	no := &Options{
		UrlParams: make(map[string]string),
		Headers:   make(map[string]string),
		Params:    make(map[string]string),
	}

	for _,o := range option{
		o(no)
	}

	return no
}